#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <climits>
#define int long long 
#define x first 
#define y second 
using namespace std ;
typedef pair<int,int> PII;
const int N = 1e5 + 10;
int a[N];
PII p[N];
int n,k;
void solve()
{
    cin >> n >> k;
    k -= 1;
    vector<int> limits;
    while(n > 0)
    {
        limits.push_back(n % 10);
        n /= 10;
    }
    //从最低位到最高位
    int len = limits.size();//3
    int res = 0;
    int f = 1;
    //5 3 1
    for(int i = 0; i < len; i++)
    {
        int cnt =  limits[i] + 1; //当前位置的数字可以取到0-limits[i]
        res += (k % cnt) * f;
        k /= cnt;
        f *= 10;
    }
    cout << res << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int t = 1;
    //cin >> t;
    while(t -- ) solve();
    return 0;
}